/**
 *
 * Created by deng on 16-1-18.
 */

module.exports = function () {
    var technology_options = {
        "area": [
            "机械电子", "生物工程", "能源环保", "化学化工", "材料科学", "其他", "其他内容"
        ],
        "origin": [
            "国内", "国外"
        ],
        "funds": [
            "10万以下", "10-30万", "30-50万", "50-100万", "100-500万", "500万以上", "面议"
        ],
        "maturity": [
            "小试", "中试", "生试"
        ],
        "number_of_cases": [
            "无", "0", "1", "2-5", "更多"
        ],
        "cooperation_form": [
            "技术入股", "技术转让", "技术许可", "委托开发", "其他", "其他内容"
        ]
    };

    var demand_options = {
        "area": [
            "机械电子", "生物工程", "能源环保", "化学化工", "材料科学", "其他", "其他内容"
        ],
        "research_funding": [
            "10万以下", "10-30万", "30-50万", "50-100万", "100-500万", "500万以上", "面议"
        ],
        "research_period": [
            "1个月", "1-3个月", "3-6个月", "6-12个月", "12-24个月", "24个月以上"
        ],
        "research_type": [
            "新产品研发", "产品技术升级", "其他", "其他内容"
        ],
        "cooperation_form": [
            "技术入股", "技术转让", "技术许可", "委托开发", "其他", "其他内容"
        ]
    };

    var getSingle = function (options) {
        var temp = Math.floor(Math.random() * options.length);
        return options[temp];
    };

    var getMultiple = function (options) {
        var temp = options.sort(function () {
            return Math.random() > 0.5 ? -1 : 1;
        });
        var index = Math.floor(Math.random() * options.length);
        return options.slice(0, index);
    };


    var demands = require('./demands.json');

    var technologies = require('./technologies.json');

    var users = require('./users.json');

    for (var index = 0; index < 20; index++) {
        var index = index;
        var demandModel = {};
        for (var property in demands[0]) {
            demandModel[property] = demands[0][property];
            switch (property) {
                case "area":
                    demandModel[property] = getMultiple(demand_options[property]);
                    break;
                case "research_funding":
                    demandModel[property] = getSingle(demand_options[property]);
                    break;
                case "research_period":
                    demandModel[property] = getSingle(demand_options[property]);
                    break;
                case "research_type":
                    demandModel[property] = getSingle(demand_options[property]);
                    break;
                case "cooperation_form":
                    demandModel[property] = getMultiple(demand_options[property]);
                    break;
            }
        }
        demandModel.id = index;
        demandModel.sn = demandModel.sn + index;
        demandModel.title = demandModel.title + index;
        var technologyModel = {};
        for (var property in technologies[0]) {
            technologyModel[property] = technologies[0][property];
            switch (property) {
                case "area":
                    technologyModel[property] = getMultiple(technology_options[property]);
                    break;
                case "origin":
                    technologyModel[property] = getSingle(technology_options[property]);
                    break;
                case "funds":
                    technologyModel[property] = getSingle(technology_options[property]);
                    break;
                case "maturity":
                    technologyModel[property] = getSingle(technology_options[property]);
                    break;
                case "number_of_cases":
                    technologyModel[property] = getSingle(technology_options[property]);
                    break;
                case "cooperation_form":
                    technologyModel[property] = getMultiple(technology_options[property]);
                    break;
            }
        }
        technologyModel.id = index;
        technologyModel.sn = technologyModel.sn + index;
        technologyModel.title = technologyModel.title + index;
        demands.push(technologyModel);
        technologies.push(technologyModel)
    }
    demands.splice(0, 1);
    technologies.splice(0, 1);

    return {
        'demands': demands,
        'technologies': technologies,
        'users': users
    }
}
;
